//
//  BaseViewController.m
//  HuaRun
//
//  Created by admin on 17/8/28.
//  Copyright © 2017年 Sunny. All rights reserved.
//

#import "BaseViewController.h"

@interface BaseViewController ()

@end

@implementation BaseViewController

#pragma mark - life cycle 
- (void)dealloc {
    NSLog(@"%@ dealloc", [self class]);
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    [self viewInit];
    [self layoutInit];
    [self dataInit];
    [self methodBind];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)viewInit {
//    self.view.backgroundColor = kRandomColor;
//    [self xhbackbtn];
        
    UIBarButtonItem *backItem = [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStyleDone target:nil action:nil];
    self.navigationItem.backBarButtonItem = backItem;


}

- (void)dataInit {

}

- (void)layoutInit {

}

- (void)methodBind {
//    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(helloMethod) name:kReachAble object:nil];
//    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(helloMethod) name:kReachUnAble object:nil];
    
}
- (void)helloMethod {
    NSLog(@"hello");
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

/** 换一个返回按钮啦*/
- (void)xhbackbtn{
    
    UIImage *backimg = [UIImage imageNamed:@"navigation_back"];
    
    //    backimg = nil;
    
    
    if ([[[UIDevice currentDevice] systemVersion] floatValue] >=11.0) {
        backimg = [UIImage imageNamed:@"navigation_back"];
        
        NSLog(@"ios 11");
        //        [backimg resizableImageWithCapInsets:UIEdgeInsetsMake(0, 0, 0, 0) resizingMode:UIImageResizingModeTile];
        backimg =  [backimg imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
        
        [self.navigationController.navigationBar setBackIndicatorImage:backimg];
        [self.navigationController.navigationBar setBackIndicatorTransitionMaskImage:backimg];
        
        UIBarButtonItem *backItem = [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStyleDone target:nil action:nil];
        self.navigationItem.backBarButtonItem = backItem;
        
        
    }else{
        
        //设置箭头颜色
        
        [[UINavigationBar appearance] setTintColor:[UIColor whiteColor]];
        
        
        UIBarMetrics barMetrics = UIBarMetricsDefault;
        
        [[UIBarButtonItem appearance] setBackButtonBackgroundImage:backimg
                                                          forState:UIControlStateNormal
                                                        barMetrics:barMetrics];
        
        [[UIBarButtonItem appearance] setBackButtonTitlePositionAdjustment:UIOffsetMake(NSIntegerMin, NSIntegerMin) forBarMetrics:barMetrics];
        
        //消除导航条返回键带的title
        [[UIBarButtonItem appearance] setBackButtonTitlePositionAdjustment:UIOffsetMake(0, 0)
                                                             forBarMetrics:barMetrics];
        
        
        
        //标题设置为空
        self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStyleDone target:nil action:nil];
        
        //            self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithImage:backimg style:UIBarButtonItemStylePlain target:self action:nil];
        
        //        self.navigationItem.title = @"";
        //    self.navigationItem.leftBarButtonItem.title = @"";
    }
    
    
    
}

-(void)nbRightImageName:(NSString *)leftImgName title:(NSString *)atitle taget:(UIViewController *)ctrl clickBlock:(void (^)(id))btnClick{
    
    UIImage *img = [UIImage imageNamed:leftImgName];
    
    UIButton *btnLeftNew = [UIButton buttonWithType:UIButtonTypeCustom];
    [btnLeftNew setFrame:CGRectMake(0, 0, 50, 50)];
    [btnLeftNew setBackgroundColor:[UIColor  clearColor]];
    [btnLeftNew addTarget:self action:@selector(customRightEventBlock:) forControlEvents:UIControlEventTouchUpInside];
    if (leftImgName != nil) {
        
        [btnLeftNew setImage:img forState:UIControlStateNormal];
    }
    
    [btnLeftNew setTitle:atitle forState:UIControlStateNormal];
    [btnLeftNew setTitleColor:[UIColor blackColor] forState:(UIControlStateNormal)];
    
    btnLeftNew.imageEdgeInsets = UIEdgeInsetsMake(0, 0, 0, -10);
    btnLeftNew.titleEdgeInsets = UIEdgeInsetsMake(0, 0, 0, -10);
    btnLeftNew.contentEdgeInsets = UIEdgeInsetsMake(0, 0, 0, -10);
    
    btnLeftNew.titleLabel.font = [UIFont systemFontOfSize:14];
    
    ctrl.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:btnLeftNew];
    self.xhRightBtnClickBlock = btnClick;
    
}

- (void)customRightEventBlock:(UIButton *)sender{
    
    NSLog(@"右边点击");
    if (self.xhRightBtnClickBlock) {
        
        self.xhRightBtnClickBlock(sender);
        
    }
    
    
}

-(void)nbLeftImageName:(NSString *)leftImgName taget:(UIViewController *)ctrl clickBlock:(void (^)(id))btnClick{
    
    UIImage *img;
    
    if (leftImgName == nil) {
        
        img = [UIImage imageNamed:@"navigation_back"];
        
    }else{
        
        img = [UIImage imageNamed:leftImgName];
        
    }
    
    UIButton *btnLeftNew = [UIButton buttonWithType:UIButtonTypeCustom];
    [btnLeftNew setFrame:CGRectMake(0, 0, 44, 44)];
    [btnLeftNew setBackgroundColor:[UIColor  clearColor]];
    [btnLeftNew addTarget:self action:@selector(customBackEventBlock:) forControlEvents:UIControlEventTouchUpInside];
    [btnLeftNew setImage:img forState:UIControlStateNormal];
    
    btnLeftNew.imageEdgeInsets = UIEdgeInsetsMake(0, -20, 0, 0);
    
    ctrl.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:btnLeftNew];
    
    
    self.xhLeftBtnClickBlock = btnClick;
    
    
}

- (void)customBackEventBlock:(UIButton *)sender{
        
    if (self.xhLeftBtnClickBlock) {
        
        self.xhLeftBtnClickBlock(sender);
        
    }
}
@end
